package cn.dengta.webapp.im.entity;

import java.util.Date;
import javax.annotation.Nonnull;

import cn.dengta.common.context.I18N;
import cn.dengta.common.model.State;
import cn.dengta.common.model.ValueProxy;
import cn.dengta.context.model.LabelI18nProxy;
import cn.dengta.context.model.Language;
import cn.dengta.context.model.UserEnumI18nKey;
import cn.dengta.webapp.base.entity.BizEntity;
import cn.dengta.webapp.im.form.GroupVerifyForm;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;

import static cn.dengta.context.model.UserEnumI18nKey.OPERATE_VERIFY_STATUS_VERIFY_FALSE;
import static cn.dengta.context.model.UserEnumI18nKey.OPERATE_VERIFY_STATUS_VERIFY_TRUE;

/**
 * 群审核日志
 *
 * @author zw
 * @since 2022-07-05
 */
@Setter
@Getter
@Accessors(chain = true)
public class GroupVerifyLog extends BizEntity {

	private static final long serialVersionUID = 1L;

	/** 操作类型: 1=群; 2=群资料 */
	private VerifyType type;
	/** 业务ID */
	private Long orderId;
	/** 审批人ID */
	private Long verifyUserId;
	/** 审批时间 */
	private Date verifyTime;
	/** 审批意见 */
	private String verifyRemark;

	public static final String TYPE = "type";
	public static final String GROUP_ID = "group_id";
	public static final String VERIFY_USER_ID = "verify_user_id";
	public static final String VERIFY_TIME = "verify_time";
	public static final String VERIFY_REMARK = "verify_remark";
	public static final String ADD_TIME = "add_time";
	public static final String STATUS = "status";
	public static final String STATE = "state";

	public static GroupVerifyLog of(GroupVerifyForm form, Long verifyUserId) {
		GroupVerifyLog groupVerifyLog = new GroupVerifyLog();
		groupVerifyLog.setOrderId(form.getOrderId());
		groupVerifyLog.setVerifyTime(new Date());
		groupVerifyLog.setVerifyUserId(verifyUserId);
		groupVerifyLog.setType(form.getVerifyType());
		groupVerifyLog.setVerifyRemark(form.getRemark());
		groupVerifyLog.setStatus(form.status);
		groupVerifyLog.setState(State.PUBLIC);
		return groupVerifyLog;
	}

	@Getter
	public enum VerifyType implements LabelI18nProxy<GroupVerifyLog.VerifyType, Integer> {
		/** 群 */
		GROUP(1, "群"),
		/** 群资料 */
		GROUP_DATA(2, "群资料"),
		;

		// 定义私有变量
		public final Integer value;
		public final String desc;

		VerifyType(Integer value, String desc) {
			this.value = value;
			this.desc = desc;
		}

		@Override
		public ValueProxy<VerifyType, java.lang.Integer> getProxy() {
			return null;
		}

		public String getI18nVerifyDesc(boolean yesOrNo, Language language, String remark) {
			String desc = getDesc(language);
			return yesOrNo ? I18N.msg(UserEnumI18nKey.VERIFY_TYPE_VERIFY_PASS, language.locale, desc) :
					I18N.msg(UserEnumI18nKey.VERIFY_TYPE_VERIFY_FAIL, language.locale, desc);
		}

		public String getDesc(@Nonnull Language language) {
			return I18N.msg(getDesc(), language.locale);
		}

	}

	public enum VerifyStatus implements LabelI18nProxy<GroupVerifyLog.VerifyStatus, Integer> {
		/** 审核不通过 */
		VERIFY_FALSE(-1, OPERATE_VERIFY_STATUS_VERIFY_FALSE),
		/** 审核通过 */
		VERIFY_TRUE(1, OPERATE_VERIFY_STATUS_VERIFY_TRUE),
		;
		public final Integer value;
		public final Integer verifyLevel;
		public final ValueProxy<VerifyStatus, Integer> proxy;

		VerifyStatus(Integer value, String label, Integer verifyLevel) {
			this.value = value;
			this.verifyLevel = verifyLevel;
			this.proxy = new ValueProxy<>(this, value, label);
		}

		VerifyStatus(Integer value, String label) {
			this(value, label, 1);
		}

		public static VerifyStatus[] getValues() {
			return ValueProxy.getCachedArray(VerifyStatus.class, VerifyStatus::values);
		}

		@Override
		public ValueProxy<VerifyStatus, Integer> getProxy() {
			return proxy;
		}
	}

}
